package com.rshang.rsdp.service.impl;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.rshang.rsdp.annotation.Log;
import com.rshang.rsdp.bean.DataGrid;
import com.rshang.rsdp.bean.Response;
import com.rshang.rsdp.common.status.ExcelStatusCode;
import com.rshang.rsdp.common.status.RyStatusCode;
import com.rshang.rsdp.common.status.StatusCode;
import com.rshang.rsdp.entity.TbRsdlHistory;
import com.rshang.rsdp.entity.TbRsdlRyxx;
import com.rshang.rsdp.entity.TbUser;
import com.rshang.rsdp.exception.RsdpSystemException;
import com.rshang.rsdp.kit.IdCardKits;
import com.rshang.rsdp.kit.StrKits;
import com.rshang.rsdp.mapper.*;
import com.rshang.rsdp.service.IExcelService;
import com.rshang.rsdp.service.ITbRsdlRyxxService;
import com.rshang.rsdp.util.excel.CellKey;
import com.rshang.rsdp.util.i18n.I18nMessage;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;

/**
 * <p>
 * 人员信息表 服务实现类
 * </p>
 *
 * @author zhangjun
 * @since 2017-08-20
 */
@Service
public class TbRsdlRyxxServiceImpl extends ServiceImpl<TbRsdlRyxxMapper, TbRsdlRyxx> implements ITbRsdlRyxxService {

    private static final Logger logger = LoggerFactory.getLogger(TbRsdlRyxxServiceImpl.class);
    @Autowired
    I18nMessage i18n;

    @Autowired
    DmRsdlGsaMapper gsMapper;

    @Autowired
    DmRsdlGsbMapper xgsMapper;

    @Autowired
    TbUserMapper czrMapper;

    @Autowired
    TbDictoryMapper dicMapper;

    @Autowired
    DmRsdlZhxxMapper zhMapper;
    
    @Autowired
    TbRsdlHistoryMapper historyMapper;

    @Autowired
    IExcelService excel;

    private static final List<CellKey> COLUMN = new ArrayList<CellKey>() {{
        add(new CellKey("公司名称", "GS_MC", "1"));//1字符型 2数字型 3日期型 4日期时间 9其他
        add(new CellKey("小公司名称", "GSB_MC", "1"));
        add(new CellKey("员工姓名", "RY_XM", "1"));
        add(new CellKey("证件类型", "RY_ZJLX", "1"));
        add(new CellKey("证件号码", "RY_ZJHM", "1"));
        add(new CellKey("负责人", "USER_XM", "1"));
        add(new CellKey("人员状态", "RY_ZT", "9"));
        add(new CellKey("联系方式", "RY_LXFS", "1"));
        add(new CellKey("电脑号", "RY_DNH", "1"));
        add(new CellKey("客户编号", "RY_KHBH", "1"));
        add(new CellKey("派遣代理", "PQDLFS", "1"));
        add(new CellKey("本人身份", "RY_BRSF", "1"));
        add(new CellKey("起始日", "RY_QSR", "3"));
        add(new CellKey("终止日", "RY_ZZR", "3"));
        add(new CellKey("下单时间", "RY_XDSJ", "3"));
        add(new CellKey("增员成功日期", "RY_ZYCGRQ", "3"));
        add(new CellKey("下增减时间", "RY_XZJSJ", "3"));
        add(new CellKey("离职时间", "RY_LZSJ", "3"));
        add(new CellKey("离职原因", "RY_LZYY", "1"));
        add(new CellKey("离职联系情况", "RY_LXQK", "1"));
        add(new CellKey("办理离职情况", "RY_BLLZQK", "1"));
        add(new CellKey("离职备注", "RY_LZBZ", "1"));
        add(new CellKey("解聘时间", "RY_JPSJ", "3"));
        add(new CellKey("社保编号", "RY_SBH", "1"));
        add(new CellKey("公积金号", "RY_GJJH", "1"));
        add(new CellKey("社保缴纳地", "SBJNDMC", "1"));
        add(new CellKey("公积金缴纳地", "GJJJNDMC", "1"));
        add(new CellKey("社保缴纳账户", "SBZHMC", "1"));
        add(new CellKey("社保缴纳账号", "SBZHBH", "1"));
        add(new CellKey("谁付款给社保局", "RY_SFKGSB", "1"));
        add(new CellKey("公积金缴纳账户", "GJJZHMC", "1"));
        add(new CellKey("公积金缴纳账号", "GJJZHBH", "1"));
        add(new CellKey("谁付款给公积金", "RY_SFKGGJJ", "1"));
        add(new CellKey("公积金费谁付款给我们", "RY_GJJSFGW", "1"));
        add(new CellKey("服务费青分/青岛", "RY_FWFJN", "1"));
        add(new CellKey("社保备注", "SBBZ", "1"));
        add(new CellKey("公积金备注", "GJJBZ", "1"));
        add(new CellKey("年度社保基数", "GZ_NDSB", "2"));
        add(new CellKey("年度公积金基数", "GZ_NDGJJ", "2"));
        add(new CellKey("公司比例", "GZ_GSBL", "2"));
        add(new CellKey("个人比例", "GZ_GRBL", "2"));
        add(new CellKey("公司缴纳金额", "GZ_GSJN", "2"));
        add(new CellKey("个人缴纳金额", "GZ_GRJN", "2"));
        add(new CellKey("缴纳合计", "GZ_SBJNHJ", "2"));
        add(new CellKey("服务费", "GZ_FWF", "2"));
        add(new CellKey("档案费", "GZ_DAF", "2"));
        add(new CellKey("人身保障", "GZ_RSBZ", "2"));
        add(new CellKey("门诊医疗", "GZ_MZYL", "2"));
        add(new CellKey("体检", "GZ_TJ", "2"));
        add(new CellKey("重大疾病", "GZ_ZDJB", "2"));
        add(new CellKey("住院补贴", "GZ_ZYBT", "2"));
        add(new CellKey("子女门诊", "GZ_ZNMZ", "2"));
        add(new CellKey("子女意外", "GZ_ZNYW", "2"));
        add(new CellKey("家财", "GZ_JC", "2"));
        add(new CellKey("联谊慰问1(生日)", "GZ_SR", "2"));
        add(new CellKey("联谊慰问1(活动)", "GZ_HD", "2"));
        add(new CellKey("取暖费", "GZ_QNF", "2"));
        add(new CellKey("薪酬及税金服务", "GZ_XCSJ", "2"));
        add(new CellKey("其他一", "GZ_QT1", "2"));
        add(new CellKey("其他一备注", "GZ_QT1BZ", "2"));
        add(new CellKey("税金", "GZ_SJ", "2"));
        add(new CellKey("录入人", "LRRMC", "1"));
        add(new CellKey("录入时间", "LRSJ", "4"));
        add(new CellKey("最后修改人", "LRRMC", "1"));
        add(new CellKey("最后修改时间", "LRSJ", "4"));
        add(new CellKey("备注", "BZ", "1"));
    }};

    private static final List<CellKey> COLUMN_IMPORT = new ArrayList<CellKey>() {{
        add(new CellKey("负责人工号", "1", true));//1字符型 2数字型 3日期型 4日期时间 9其他
        add(new CellKey("负责人", "1", false));
        add(new CellKey("社保缴纳地", "1", true));
        add(new CellKey("公积金缴纳地", "1", true));
        add(new CellKey("公司名称", "1", true));
        add(new CellKey("小公司名称", "1", true));
        add(new CellKey("员工姓名", "1", 100, true));
        add(new CellKey("证件类型", "1", 20, true));
        add(new CellKey("证件号码", "1", 30, true));
        add(new CellKey("联系电话", "1", 100, false));
        add(new CellKey("电脑号", "1", 50, false));
        add(new CellKey("客户编号", "1", 50, false));
        add(new CellKey("派遣/代理", "1", false));
        add(new CellKey("本人身份", "1", 100, false));
        add(new CellKey("社保编号", "1", 30, false));
        add(new CellKey("公积金号", "1", 30, false));
        add(new CellKey("起始日", "3", true));
        add(new CellKey("终止日", "3", false));
        add(new CellKey("下单时间", "3", true));
        add(new CellKey("增员成功日期", "3", false));
        add(new CellKey("下增减时间", "3", false));
        add(new CellKey("离职时间", "3", false));
        add(new CellKey("离职原因", "1", 200, false));
        add(new CellKey("离职联系情况", "1", 200, false));
        add(new CellKey("办理离职情况", "1", 200, false));
        add(new CellKey("离职备注", "1", 200, false));
        add(new CellKey("解聘时间", "3", false));
        add(new CellKey("员工社保缴纳账户", "1", false));
        add(new CellKey("谁付款给社保局", "1", 200, false));
        add(new CellKey("社保费谁付款给我们", "1", 200, false));
        add(new CellKey("员工公积金缴纳账户", "1", false));
        add(new CellKey("谁付款给公积金中心", "1", 200, false));
        add(new CellKey("公积金费谁付给我们", "1", 200, false));
        add(new CellKey("服务费青分/青岛", "1", 200, false));
        add(new CellKey("备注", "1", 400, false));
        add(new CellKey("社保基数", "2", false));
        add(new CellKey("社保备注", "1", 200, false));
        add(new CellKey("公积金基数", "2", false));
        add(new CellKey("比例(公司)", "2", false));
        add(new CellKey("比例(个人)", "2", false));
        add(new CellKey("金额(公司)", "2", false));
        add(new CellKey("金额(个人)", "2", false));
        add(new CellKey("金额(合计)", "2", false));
        add(new CellKey("公积金备注", "1", 200, false));
        add(new CellKey("服务费", "2", false));
        add(new CellKey("档案费", "2", false));
        add(new CellKey("人身保障", "2", false));
        add(new CellKey("门诊医疗", "2", false));
        add(new CellKey("体检", "2", false));
        add(new CellKey("重大疾病", "2", false));
        add(new CellKey("住院补贴", "2", false));
        add(new CellKey("子女门诊", "2", false));
        add(new CellKey("子女意外", "2", false));
        add(new CellKey("家财", "2", false));
        add(new CellKey("联谊慰问(生日)", "2", false));
        add(new CellKey("联谊慰问(活动)", "2", false));
        add(new CellKey("取暖费", "2", false));
        add(new CellKey("薪酬及税金服务", "2", false));
        add(new CellKey("其他一", "2", false));
        add(new CellKey("其他一备注", "1", 200, false));
        add(new CellKey("税金", "2", false));
    }};
    private static final List<CellKey> COLUMN_JP = new ArrayList<CellKey>() {{
        add(new CellKey("公司名称", "GS_MC", "1"));//1字符型 2数字型 3日期型 4日期时间 9其他
        add(new CellKey("小公司名称", "GSB_MC", "1"));
        add(new CellKey("员工姓名", "RY_XM", "1"));
        add(new CellKey("证件类型", "RY_ZJLX", "1"));
        add(new CellKey("证件号码", "RY_ZJHM", "1"));
        add(new CellKey("负责人", "USER_XM", "1"));
        add(new CellKey("人员状态", "RY_ZT", "9"));
        add(new CellKey("联系方式", "RY_LXFS", "1"));
        add(new CellKey("离职时间", "RY_LZSJ", "3"));
        add(new CellKey("离职原因", "RY_LZYY", "1"));
        add(new CellKey("离职联系情况", "RY_LXQK", "1"));
        add(new CellKey("办理离职情况", "RY_BLLZQK", "1"));
        add(new CellKey("离职备注", "RY_LZBZ", "1"));
        add(new CellKey("解聘时间", "RY_JPSJ", "3"));
        add(new CellKey("社保编号", "RY_SBH", "1"));
        add(new CellKey("社保缴纳账户", "SBZHMC", "1"));
        add(new CellKey("社保缴纳账号", "SBZHBH", "1"));
        add(new CellKey("备注", "BZ", "1"));
    }};

    @Override
    public DataGrid getYbcxList(Page<HashMap> page, HttpServletRequest request, String czr, boolean isManager) {
        page.setRecords(this.baseMapper.getYbcxList(page,StrKits.emptyToStr(StringUtils.isEmpty(request.getParameter("cxyf")) ? DateTime.now().toString("yyyyMM") : StrKits.emptyToStr(request.getParameter("cxyf"))), czr, isManager, StrKits.emptyToStr(request.getParameter("xm")), StrKits.emptyToStr(request.getParameter("gsmc"))));
        return new DataGrid(page.getRecords(), page.getTotal());
    }

    @Log(module = "月报统计", desc = "月报统计导出")
    @Override
    public Workbook ybcxListExport(HttpServletRequest request, String czr, boolean isManager) {
        List<HashMap> list = this.baseMapper.getYbcxListExport(StrKits.emptyToStr(request.getParameter("cxyf")), czr, isManager, StrKits.emptyToStr(request.getParameter("xm")), StrKits.emptyToStr(request.getParameter("gsmc")));
        Workbook wb = new HSSFWorkbook();
        Sheet sheet = wb.createSheet("月报统计");
        Row row = null;
        Cell cell = null;
        int rowIndex = 0;

        //自动列宽
        //sheet.autoSizeColumn(1);
        sheet.setColumnWidth(0, 5000);
        sheet.setColumnWidth(1, 5000);
        sheet.setColumnWidth(2, 5000);
        sheet.setColumnWidth(3, 5000);
        //创建字体
        HSSFFont headFont = (HSSFFont) wb.createFont();
        headFont.setFontHeightInPoints((short) 14);//设置字体大小
        headFont.setBold(true);

        HSSFFont contFont = (HSSFFont) wb.createFont();
        contFont.setFontHeightInPoints((short) 12);//设置字体大小

        HSSFCellStyle headStyle = (HSSFCellStyle) wb.createCellStyle();
        headStyle.setFont(headFont);
        headStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        headStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.ORANGE.getIndex());
        headStyle.setBorderBottom(BorderStyle.THIN); //下边框
        headStyle.setBorderLeft(BorderStyle.THIN);//左边框
        headStyle.setBorderTop(BorderStyle.THIN);//上边框
        headStyle.setBorderRight(BorderStyle.THIN);//右边框
        headStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
        headStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直集中

        HSSFCellStyle contStyle = (HSSFCellStyle) wb.createCellStyle();
        contStyle.setFont(contFont);
        contStyle.setBorderBottom(BorderStyle.THIN); //下边框
        contStyle.setBorderLeft(BorderStyle.THIN);//左边框
        contStyle.setBorderTop(BorderStyle.THIN);//上边框
        contStyle.setBorderRight(BorderStyle.THIN);//右边框
        contStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
        contStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直集中

        //构建表头
        row = sheet.createRow(rowIndex++);
        row.setHeight((short) 500);//行高
        cell = row.createCell(0);
        cell.setCellType(CellType.STRING);
        cell.setCellStyle(headStyle);
        cell.setCellValue("公司名称");

        cell = row.createCell(1);
        cell.setCellType(CellType.STRING);
        cell.setCellStyle(headStyle);
        cell.setCellValue("负责人");

        cell = row.createCell(2);
        cell.setCellType(CellType.STRING);
        cell.setCellStyle(headStyle);
        cell.setCellValue("在职人数");

        cell = row.createCell(3);
        cell.setCellType(CellType.STRING);
        cell.setCellStyle(headStyle);
        cell.setCellValue("新增人数");

        cell = row.createCell(4);
        cell.setCellType(CellType.STRING);
        cell.setCellStyle(headStyle);
        cell.setCellValue("减员人数");

        for (HashMap record : list) {
            row = sheet.createRow(rowIndex++);
            row.setHeight((short) 500);//excel行高*20
            cell = row.createCell(0);
            cell.setCellType(CellType.STRING);
            cell.setCellStyle(contStyle);
            cell.setCellValue(StrKits.emptyToStr(record.get("GS_MC")));

            cell = row.createCell(1);
            cell.setCellType(CellType.STRING);
            cell.setCellStyle(contStyle);
            cell.setCellValue(StrKits.emptyToStr(record.get("USER_XM")));

            cell = row.createCell(2);
            cell.setCellType(CellType.STRING);
            cell.setCellStyle(contStyle);
            cell.setCellValue(StrKits.emptyToStr(record.get("DYZZ")));

            cell = row.createCell(3);
            cell.setCellType(CellType.STRING);
            cell.setCellStyle(contStyle);
            cell.setCellValue(StrKits.emptyToStr(record.get("DYXZ")));
            cell = row.createCell(3);
            cell.setCellType(CellType.STRING);
            cell.setCellStyle(contStyle);
            cell.setCellValue(StrKits.emptyToStr(record.get("DYJY")));
        }

        return wb;
    }

    @Override
    public HashMap getZsTbTj(String czr, boolean isManager) {
        String cxyf = DateTime.now().toString("yyyyMM");
        HashMap zsMap = this.baseMapper.getZsTj(cxyf);

        if (!isManager) {
            HashMap bysMap = this.baseMapper.getZsTjByUserId(cxyf, czr);
            zsMap.put("ZZ_BYS", bysMap.get("ZZ_BYS"));
            zsMap.put("WB_BYS", bysMap.get("WB_BYS"));
            zsMap.put("XZ_BYS", bysMap.get("XZ_BYS"));
            zsMap.put("JY_BYS", bysMap.get("JY_BYS"));
        } else {
            zsMap.put("ZZ_BYS", zsMap.get("ZZ_ZS"));
            zsMap.put("WB_BYS", zsMap.get("WB_ZS"));
            zsMap.put("XZ_BYS", zsMap.get("XZ_ZS"));
            zsMap.put("JY_BYS", zsMap.get("JY_ZS"));
        }
        //System.out.println(zsMap);
        return zsMap;
    }

    @Override
    public HashMap getZzNdTj(String czr, boolean manager) {
        return this.baseMapper.getZzNdTj(DateTime.now().toString("yyyy"), czr, manager);
    }

    @Override
    public List<HashMap> getRyxxByCzr(HttpServletRequest request, String czr) {
        return this.baseMapper.getRyxxByCzrGs(czr, StrKits.emptyToStr(request.getParameter("gsid")), StrKits.emptyToStr(request.getParameter("xgsid")));
    }

    @Override
    public DataGrid getRyxxList(Page<HashMap> page, HttpServletRequest request, String czr, String lx) {
        String gsmc = StrKits.emptyToStr(request.getParameter("gsmc"));
        String xgsmc = StrKits.emptyToStr(request.getParameter("xgsmc"));
        String lrr = StrKits.emptyToStr(request.getParameter("lrr"));
        String xm = StrKits.emptyToStr(request.getParameter("xm"));
        String ryzt = StrKits.emptyToStr(request.getParameter("ryzt"));
        String sfzhm = StrKits.emptyToStr(request.getParameter("sfzhm"));
        String dnh = StrKits.emptyToStr(request.getParameter("dnh"));
        String khbh = StrKits.emptyToStr(request.getParameter("khbh"));
        String cxrqq = StrKits.emptyToStr(request.getParameter("cxrqq"));
        String cxrqz = StringUtils.isEmpty(request.getParameter("cxrqz")) ? "" : request.getParameter("cxrqz") + " 23:59:59";
        String sort = StrKits.emptyToStr(request.getParameter("sort"));
        String order = StrKits.emptyToStr(request.getParameter("order"));
        String lzyy = StrKits.emptyToStr(request.getParameter("lzyy"));
        String yc = StrKits.emptyToStr(request.getParameter("yc"));
        String lxqk = StrKits.emptyToStr(request.getParameter("lxqk"));

        page.setRecords(this.baseMapper.getRyList(page, lrr, lx, gsmc, xgsmc, xm, ryzt, sfzhm, dnh, khbh, cxrqq, cxrqz,lzyy,yc,lxqk, czr, StrKits.getOrderBy(sort, order)));
        return new DataGrid(page.getRecords(), page.getTotal());
    }

    @Log(module = "人员信息", desc = "新增")
    @Override
    public Response addSave(HttpServletRequest request, String czr) {
        TbRsdlRyxx ryxx = new TbRsdlRyxx();
        ryxx.setRyId(StrKits.uuid());
        ryxx.setGsId(StrKits.emptyToStr(request.getParameter("sel_gs")));
        ryxx.setGsbId(StrKits.emptyToStr(request.getParameter("sel_xgs")));
        ryxx.setRyXm(StrKits.emptyToStr(request.getParameter("ry_xm")));
        ryxx.setRyZjlx(StrKits.emptyToStr(request.getParameter("sel_zjlx")));
        ryxx.setRyZjhm(StrKits.emptyToStr(request.getParameter("ry_zjhm")));
        ryxx.setRyLxfs(StrKits.emptyToStr(request.getParameter("ry_lxfs")));
        ryxx.setRyKhbh(StrKits.emptyToStr(request.getParameter("ry_khbh")));
        ryxx.setRyPqdl(StrKits.emptyToStr(request.getParameter("sel_pqdlfs")));
        ryxx.setRyBrsf(StrKits.emptyToStr(request.getParameter("ry_brsf")));
        ryxx.setRyDnh(StrKits.emptyToStr(request.getParameter("ry_dnh")));
        ryxx.setRyQsr(StringUtils.isEmpty(request.getParameter("ry_qsr")) ? null : new DateTime(request.getParameter("ry_qsr")).toDate());
        //ryxx.setRyZzr(StringUtils.isEmpty(request.getParameter("ry_zzr"))?null:new DateTime(request.getParameter("ry_zzr")).toDate());
        ryxx.setRyXdsj(StringUtils.isEmpty(request.getParameter("ry_xdsj")) ? null : new DateTime(request.getParameter("ry_xdsj")).toDate());
        ryxx.setRyXzjsj(StringUtils.isEmpty(request.getParameter("ry_xzjsj")) ? null : new DateTime(request.getParameter("ry_xzjsj")).toDate());
        //ryxx.setRyLzsj(StringUtils.isEmpty(request.getParameter("ry_lzsj"))?null:new DateTime(request.getParameter("ry_lzsj")).toDate());
        //ryxx.setRyBllzqk(StrKits.emptyToStr(request.getParameter("ry_blzqk")));
        //ryxx.setRyJpsj(StringUtils.isEmpty(request.getParameter("ry_jpsj"))?null:new DateTime(request.getParameter("ry_jpsj")).toDate());
        ryxx.setRySbh(StrKits.emptyToStr(request.getParameter("ry_sbh")));
        ryxx.setRyGjjh(StrKits.emptyToStr(request.getParameter("ry_gjjh")));
        ryxx.setSbjndDm(StrKits.emptyToStr(request.getParameter("sel_sbjnd")));
        ryxx.setGjjjndDm(StrKits.emptyToStr(request.getParameter("sel_gjjjnd")));
        ryxx.setSbjnzhDm(StrKits.emptyToStr(request.getParameter("sel_sbzh")));
        ryxx.setGjjzhDm(StrKits.emptyToStr(request.getParameter("sel_gjjzh")));
        ryxx.setRySfkgsb(StrKits.emptyToStr(request.getParameter("ry_sfkgsb")));
        ryxx.setRySfkggjj(StrKits.emptyToStr(request.getParameter("ry_sfkggjj")));
        ryxx.setRyFwfjn(StrKits.emptyToStr(request.getParameter("ry_fwfjn")));
        ryxx.setRyGjjsfgw(StrKits.emptyToStr(request.getParameter("ry_gjjsfkgw")));
        ryxx.setRySbfsfgw(StrKits.emptyToStr(request.getParameter("ry_sbfsfkgw")));
        ryxx.setGzNdsb(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_ndsb"), "0")));
        ryxx.setGzNdgjj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_ndgjj"), "0")));
        ryxx.setGzGrbl(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_grbl"), "0")));
        ryxx.setGzGsbl(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_gsbl"), "0")));
        ryxx.setGzGrjn(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_grjn"), "0")));
        ryxx.setGzGsjn(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_gsjn"), "0")));
        ryxx.setGzSbjnhj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_sbjnhj"), "0")));
        ryxx.setSbbz(StrKits.emptyToStr(request.getParameter("gz_sbbz")));
        ryxx.setGjjbz(StrKits.emptyToStr(request.getParameter("gz_gjjbz")));
        ryxx.setGzFwf(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_fwf"), "0")));
        ryxx.setGzDaf(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_daf"), "0")));
        ryxx.setGzRsbz(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_rsbz"), "0")));
        ryxx.setGzMzyl(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_mzyl"), "0")));
        ryxx.setGzTj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_tj"), "0")));
        ryxx.setGzZdjb(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_zdjb"), "0")));
        ryxx.setGzZybt(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_zybt"), "0")));
        ryxx.setGzZnmz(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_znmz"), "0")));
        ryxx.setGzZnyw(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_znyw"), "0")));
        ryxx.setGzJc(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_jc"), "0")));
        ryxx.setGzSr(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_sr"), "0")));
        ryxx.setGzHd(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_hd"), "0")));
        ryxx.setGzQnf(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_qnf"), "0")));
        ryxx.setGzXcsj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_xcsj"), "0")));
        ryxx.setGzQt1(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_qt1"), "0")));
        ryxx.setGzQt1bz(StrKits.emptyToStr(request.getParameter("gz_qt1bz")));
        ryxx.setGzSj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_qt1"), "0")));
        ryxx.setBz(StrKits.emptyToStr(request.getParameter("ry_bz")));
        ryxx.setLrr(czr);
        ryxx.setXgr(czr);
        ryxx.setDlr(StrKits.emptyToStr(request.getParameter("sel_dlr")));
        ryxx.setRyZycgrq(StringUtils.isEmpty(request.getParameter("ry_zycgrq")) ? null : new DateTime(request.getParameter("ry_zycgrq")).toDate());
        if (ryxx.getRyZycgrq() != null) {
            ryxx.setRyZt("2");
        }
        ryxx.setBclxDm(StrKits.emptyToStr(request.getParameter("hid_bclx")));
        ryxx.setGzSndsb(ryxx.getGzNdsb());
        ryxx.setGzSndgjj(ryxx.getGzNdgjj());

        if (this.baseMapper.insert(ryxx) > 0) {
            return new Response(StatusCode.SUCCESS.getCode(), i18n.getMessage(StatusCode.SUCCESS.getKey()));
        } else {
            return new Response(StatusCode.OPER_FAILED.getCode(), i18n.getMessage(StatusCode.OPER_FAILED.getKey()));
        }
    }

    @Override
    public TbRsdlRyxx get(HttpServletRequest request) {
        TbRsdlRyxx result = this.selectById(StrKits.emptyToStr(request.getParameter("id")));
        if (result == null) {
            throw new RsdpSystemException(RyStatusCode.RY_NOTFOUND.getCode(), i18n.getMessage(RyStatusCode.RY_NOTFOUND.getKey()));
        } else {
        		result.setGzGrjn1(String.valueOf(Math.floor(result.getGzGrjn().doubleValue())));
        		result.setGzGsjn1(String.valueOf(Math.floor(result.getGzGsjn().doubleValue())));
        		result.setGzSbjnhj1(String.valueOf(Math.floor(result.getGzSbjnhj().doubleValue())));
                setRyxnzt(result,result.getIsDjp(),result.getIsCxwt());
            return result;
        }
    }
    private void setRyxnzt(TbRsdlRyxx result,String isDjp,String isCxwt){
        if("1".equals(result.getRyZt()))
        {
            //未办
            result.setRyxnzt("1");
            return;
        }
        if("2".equals(result.getRyZt()))
        {
            //已办
            result.setRyxnzt("2");
            return;
        }
        if("3".equals(result.getRyZt())&&"1".equals(result.getIsCxwt()))
        {
            //撤销委托
            result.setRyxnzt("31");
            return;
        }
        if("3".equals(result.getRyZt())&&"0".equals(result.getIsCxwt()))
        {
            //离职
            result.setRyxnzt("3");
            return;
        }
        if("9".equals(result.getRyZt())&&"0".equals(result.getIsDjp()))
        {
            //离职异常
            result.setRyxnzt("9");
            return;
        }
        if("4".equals(result.getRyZt())&&"0".equals(result.getIsDjp()))
        {
            //解聘
            result.setRyxnzt("4");
            return;
        }
        if("4".equals(result.getRyZt())&&"1".equals(result.getIsDjp()))
        {
            //待解聘
            result.setRyxnzt("41");
            return;
        }
        if("9".equals(result.getRyZt())&&"1".equals(result.getIsDjp()))
        {
            //待解聘异常
            result.setRyxnzt("91");
            return;
        }

    }

    @Log(module = "人员信息", desc = "编辑")
    @Override
    public Response editSave(HttpServletRequest request, String czr,String czrMc) {
        String ryid = StrKits.emptyToStr(request.getParameter("hid_id"));
        TbRsdlRyxx ryxx = this.baseMapper.selectById(ryid);
        if (ryxx == null) {
            throw new RsdpSystemException(RyStatusCode.RY_NOTFOUND.getCode(), i18n.getMessage(RyStatusCode.RY_NOTFOUND.getKey()));
        }
        ryxx.setGsId(StrKits.emptyToStr(request.getParameter("sel_gs")));
        ryxx.setGsbId(StrKits.emptyToStr(request.getParameter("sel_xgs")));
        ryxx.setRyXm(StrKits.emptyToStr(request.getParameter("ry_xm")));
        ryxx.setRyZjlx(StrKits.emptyToStr(request.getParameter("sel_zjlx")));
        ryxx.setRyZjhm(StrKits.emptyToStr(request.getParameter("ry_zjhm")));
        ryxx.setRyLxfs(StrKits.emptyToStr(request.getParameter("ry_lxfs")));
        ryxx.setRyKhbh(StrKits.emptyToStr(request.getParameter("ry_khbh")));
        ryxx.setRyPqdl(StrKits.emptyToStr(request.getParameter("sel_pqdlfs")));
        ryxx.setRyBrsf(StrKits.emptyToStr(request.getParameter("ry_brsf")));
        ryxx.setRyDnh(StrKits.emptyToStr(request.getParameter("ry_dnh")));
        ryxx.setRyQsr(StringUtils.isEmpty(request.getParameter("ry_qsr")) ? null : new DateTime(request.getParameter("ry_qsr")).toDate());
        //ryxx.setRyZzr(StringUtils.isEmpty(request.getParameter("ry_zzr"))?null:new DateTime(request.getParameter("ry_zzr")).toDate());
        ryxx.setRyXdsj(StringUtils.isEmpty(request.getParameter("ry_xdsj")) ? null : new DateTime(request.getParameter("ry_xdsj")).toDate());
        //ryxx.setRyXzjsj(StringUtils.isEmpty(request.getParameter("ry_xzjsj"))?null:new DateTime(request.getParameter("ry_xzjsj")).toDate());
        //ryxx.setRyLzsj(StringUtils.isEmpty(request.getParameter("ry_lzsj"))?null:new DateTime(request.getParameter("ry_lzsj")).toDate());
        //ryxx.setRyBllzqk(StrKits.emptyToStr(request.getParameter("ry_blzqk")));
        //ryxx.setRyJpsj(StringUtils.isEmpty(request.getParameter("ry_jpsj"))?null:new DateTime(request.getParameter("ry_jpsj")).toDate());
        ryxx.setRySbh(StrKits.emptyToStr(request.getParameter("ry_sbh")));
        ryxx.setRyGjjh(StrKits.emptyToStr(request.getParameter("ry_gjjh")));
        ryxx.setSbjndDm(StrKits.emptyToStr(request.getParameter("sel_sbjnd")));
        ryxx.setGjjjndDm(StrKits.emptyToStr(request.getParameter("sel_gjjjnd")));
        ryxx.setSbjnzhDm(StrKits.emptyToStr(request.getParameter("sel_sbzh")));
        ryxx.setGjjzhDm(StrKits.emptyToStr(request.getParameter("sel_gjjzh")));
        ryxx.setRySfkgsb(StrKits.emptyToStr(request.getParameter("ry_sfkgsb")));
        ryxx.setRySfkggjj(StrKits.emptyToStr(request.getParameter("ry_sfkggjj")));
        ryxx.setRyFwfjn(StrKits.emptyToStr(request.getParameter("ry_fwfjn")));
        ryxx.setRyGjjsfgw(StrKits.emptyToStr(request.getParameter("ry_gjjsfkgw")));
        ryxx.setRySbfsfgw(StrKits.emptyToStr(request.getParameter("ry_sbfsfkgw")));
        ryxx.setGzSndsb(ryxx.getGzNdsb());
        ryxx.setGzSndgjj(ryxx.getGzNdgjj());
        ryxx.setGzNdsb(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_ndsb"), "0")));
        ryxx.setGzNdgjj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_ndgjj"), "0")));
        ryxx.setGzGrbl(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_grbl"), "0")));
        ryxx.setGzGsbl(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_gsbl"), "0")));
        ryxx.setGzGrjn(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_grjn"), "0")));
        ryxx.setGzGsjn(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_gsjn"), "0")));
        ryxx.setGzSbjnhj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_sbjnhj"), "0")));
        ryxx.setSbbz(StrKits.emptyToStr(request.getParameter("gz_sbbz")));
        ryxx.setGjjbz(StrKits.emptyToStr(request.getParameter("gz_gjjbz")));
        ryxx.setGzFwf(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_fwf"), "0")));
        ryxx.setGzDaf(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_daf"), "0")));
        ryxx.setGzRsbz(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_rsbz"), "0")));
        ryxx.setGzMzyl(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_mzyl"), "0")));
        ryxx.setGzTj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_tj"), "0")));
        ryxx.setGzZdjb(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_zdjb"), "0")));
        ryxx.setGzZybt(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_zybt"), "0")));
        ryxx.setGzZnmz(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_znmz"), "0")));
        ryxx.setGzZnyw(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_znyw"), "0")));
        ryxx.setGzJc(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_jc"), "0")));
        ryxx.setGzSr(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_sr"), "0")));
        ryxx.setGzHd(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_hd"), "0")));
        ryxx.setGzQnf(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_qnf"), "0")));
        ryxx.setGzXcsj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_xcsj"), "0")));
        ryxx.setGzQt1(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_qt1"), "0")));
        ryxx.setGzQt1bz(StrKits.emptyToStr(request.getParameter("gz_qt1bz")));
        ryxx.setGzSj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_sj"), "0")));
        ryxx.setBz(StrKits.emptyToStr(request.getParameter("ry_bz")));
        ryxx.setXgr(czr);
        ryxx.setXgsj(new Date());
        ryxx.setDlr(StrKits.emptyToStr(request.getParameter("sel_dlr")));
        String oldRyZt = StrKits.emptyToStr(request.getParameter("hid_zt"));//人员原状态
        String ryzt = StrKits.emptyToStr(request.getParameter("sel_ryzt"));//人员当前状态
        //设置人员状态
        changRyzt(ryzt, request, ryxx);
        //修改社保基数
        if(ryxx.getGzNdsb().compareTo(ryxx.getGzSndsb())!=0) {
        		TbRsdlHistory history = new TbRsdlHistory();
        		history.setHisId(StrKits.uuid());
        		history.setObjId(ryid);
        		history.setHisType("01");
        		history.setXgr(czr);
        		history.setXgsj(new Date());
        		history.setHisCont(i18n.getMessage("his.sndsb", new Object[] {StrKits.getNowDateStr("yyyy年MM月dd日"),czrMc,ryxx.getGzSndsb().setScale(2,BigDecimal.ROUND_HALF_UP).toPlainString(),ryxx.getGzNdsb().setScale(2,BigDecimal.ROUND_HALF_UP).toPlainString()}));
        		historyMapper.insert(history);
        }
        //修改公积金基数
        if(ryxx.getGzNdgjj().compareTo(ryxx.getGzSndgjj())!=0) {
	    		TbRsdlHistory history = new TbRsdlHistory();
	    		history.setHisId(StrKits.uuid());
	    		history.setObjId(ryid);
	    		history.setHisType("01");
	    		history.setXgr(czr);
	    		history.setXgsj(new Date());
	    		history.setHisCont(i18n.getMessage("his.sndgjj", new Object[] {StrKits.getNowDateStr("yyyy年MM月dd日"),czrMc,ryxx.getGzSndgjj().setScale(2,BigDecimal.ROUND_HALF_UP).toPlainString(),ryxx.getGzNdgjj().setScale(2,BigDecimal.ROUND_HALF_UP).toPlainString()}));
	    		historyMapper.insert(history);
	    }
        
        logger.debug("人员旧状态为{} 新状态{}:{}", getRyZtMc(oldRyZt), getRyZtMc(ryzt), ryxx);

        if (this.baseMapper.updateAllColumnById(ryxx) > 0) {
            return new Response(StatusCode.SUCCESS.getCode(), i18n.getMessage(StatusCode.SUCCESS.getKey()));
        } else {
            return new Response(StatusCode.OPER_FAILED.getCode(), i18n.getMessage(StatusCode.OPER_FAILED.getKey()));
        }
    }

    private String getRyZtMc(String ryzt) {
        switch (ryzt) {
            case "1":
                return "未办";
            case "2":
                return "已办";
            case "31":
                return "撤销委托";
            case "3":
                return "离职";
            case "4":
                return "解聘";
            case "41":
                return "待解聘";
            case "9":
                return "离职异常";
            case "91":
                return "待解聘异常";
            default:
                return "";
        }
    }

    private void changRyzt(String ryzt, HttpServletRequest request, TbRsdlRyxx ryxx) {
        if ("1".equals(ryzt))//未办状态
        {
            ryxx.setRyZt("1");
            ryxx.setRyZycgrq(null);
            ryxx.setRyZzr(null);
            ryxx.setRyLzsj(null);
            ryxx.setRyLzyy("");
            ryxx.setRyLzbz("");
            ryxx.setRyLxqk("");
            ryxx.setRyBllzqk("");
            ryxx.setRyJpsj(null);
            ryxx.setRyXzjsj(StringUtils.isEmpty(request.getParameter("ry_xzjsj")) ? null : new DateTime(request.getParameter("ry_xzjsj")).toDate());
            ryxx.setIsDjp("0");
            ryxx.setIsCxwt("0");
        }
        if ("2".equals(ryzt))//已办状态
        {
            ryxx.setRyZt("2");
            ryxx.setRyZycgrq(StringUtils.isEmpty(request.getParameter("ry_zycgrq")) ? null : new DateTime(request.getParameter("ry_zycgrq")).toDate());
            ryxx.setRyXzjsj(StringUtils.isEmpty(request.getParameter("ry_xzjsj")) ? null : new DateTime(request.getParameter("ry_xzjsj")).toDate());
            ryxx.setRyZzr(null);
            ryxx.setRyLzsj(null);
            ryxx.setRyLzyy("");
            ryxx.setRyLzbz("");
            ryxx.setRyLxqk("");
            ryxx.setRyBllzqk("");
            ryxx.setRyJpsj(null);
            ryxx.setIsDjp("0");
            ryxx.setIsCxwt("0");
        }
        if ("31".equals(ryzt))//撤销委托
        {
            ryxx.setRyZt("3");
            ryxx.setRyZycgrq(StringUtils.isEmpty(request.getParameter("ry_zycgrq")) ? null : new DateTime(request.getParameter("ry_zycgrq")).toDate());
            ryxx.setRyXzjsj(StringUtils.isEmpty(request.getParameter("ry_xzjsj")) ? null : new DateTime(request.getParameter("ry_xzjsj")).toDate());
            ryxx.setRyZzr(StringUtils.isEmpty(request.getParameter("ry_zzr")) ? null : new DateTime(request.getParameter("ry_zzr")).toDate());
            ryxx.setRyLzsj(StringUtils.isEmpty(request.getParameter("ry_lzsj")) ? null : new DateTime(request.getParameter("ry_lzsj")).toDate());
            ryxx.setRyLzyy("");
            ryxx.setRyLzbz("");
            ryxx.setRyLxqk("");
            ryxx.setRyBllzqk("");
            ryxx.setRyJpsj(null);
            ryxx.setIsDjp("0");
            ryxx.setIsCxwt("1");
        }
        if ("3".equals(ryzt))//离职状态
        {
            ryxx.setRyZt("3");
            ryxx.setRyZycgrq(StringUtils.isEmpty(request.getParameter("ry_zycgrq")) ? null : new DateTime(request.getParameter("ry_zycgrq")).toDate());
            ryxx.setRyXzjsj(StringUtils.isEmpty(request.getParameter("ry_xzjsj")) ? null : new DateTime(request.getParameter("ry_xzjsj")).toDate());
            ryxx.setRyZzr(StringUtils.isEmpty(request.getParameter("ry_zzr")) ? null : new DateTime(request.getParameter("ry_zzr")).toDate());
            ryxx.setRyLzsj(StringUtils.isEmpty(request.getParameter("ry_lzsj")) ? null : new DateTime(request.getParameter("ry_lzsj")).toDate());
            ryxx.setRyLzyy(StrKits.emptyToStr(request.getParameter("ry_lzyy")));
            ryxx.setRyLzbz(StrKits.emptyToStr(request.getParameter("ry_lzbz")));
            ryxx.setRyLxqk(StrKits.emptyToStr(request.getParameter("ry_lxqk")));
            ryxx.setRyBllzqk(StrKits.emptyToStr(request.getParameter("ry_bllzqk")));
            ryxx.setRyJpsj(null);
            ryxx.setIsDjp("0");
            ryxx.setIsCxwt("0");
        }
        if ("4".equals(ryzt))//解聘状态
        {
            ryxx.setRyZt("4");
            ryxx.setRyZycgrq(StringUtils.isEmpty(request.getParameter("ry_zycgrq")) ? null : new DateTime(request.getParameter("ry_zycgrq")).toDate());
            ryxx.setRyXzjsj(StringUtils.isEmpty(request.getParameter("ry_xzjsj")) ? null : new DateTime(request.getParameter("ry_xzjsj")).toDate());
            ryxx.setRyZzr(StringUtils.isEmpty(request.getParameter("ry_zzr")) ? null : new DateTime(request.getParameter("ry_zzr")).toDate());
            ryxx.setRyLzsj(StringUtils.isEmpty(request.getParameter("ry_lzsj")) ? null : new DateTime(request.getParameter("ry_lzsj")).toDate());
            ryxx.setRyLzyy(StrKits.emptyToStr(request.getParameter("ry_lzyy")));
            ryxx.setRyLzbz(StrKits.emptyToStr(request.getParameter("ry_lzbz")));
            ryxx.setRyLxqk(StrKits.emptyToStr(request.getParameter("ry_lxqk")));
            ryxx.setRyBllzqk(StrKits.emptyToStr(request.getParameter("ry_bllzqk")));
            ryxx.setRyJpsj(StringUtils.isEmpty(request.getParameter("ry_jpsj")) ? null : new DateTime(request.getParameter("ry_jpsj")).toDate());
            ryxx.setIsDjp("0");
            ryxx.setIsCxwt("0");
        }
        if ("41".equals(ryzt))//待解聘
        {
            ryxx.setRyZt("4");
            ryxx.setRyZycgrq(StringUtils.isEmpty(request.getParameter("ry_zycgrq")) ? null : new DateTime(request.getParameter("ry_zycgrq")).toDate());
            ryxx.setRyXzjsj(StringUtils.isEmpty(request.getParameter("ry_xzjsj")) ? null : new DateTime(request.getParameter("ry_xzjsj")).toDate());
            ryxx.setRyZzr(StringUtils.isEmpty(request.getParameter("ry_zzr")) ? null : new DateTime(request.getParameter("ry_zzr")).toDate());
            ryxx.setRyLzsj(StringUtils.isEmpty(request.getParameter("ry_lzsj")) ? null : new DateTime(request.getParameter("ry_lzsj")).toDate());
            ryxx.setRyLzyy(StrKits.emptyToStr(request.getParameter("ry_lzyy")));
            ryxx.setRyLzbz(StrKits.emptyToStr(request.getParameter("ry_lzbz")));
            ryxx.setRyLxqk(StrKits.emptyToStr(request.getParameter("ry_lxqk")));
            ryxx.setRyBllzqk(StrKits.emptyToStr(request.getParameter("ry_bllzqk")));
            ryxx.setRyJpsj(StringUtils.isEmpty(request.getParameter("ry_jpsj")) ? null : new DateTime(request.getParameter("ry_jpsj")).toDate());
            ryxx.setIsDjp("1");
            ryxx.setIsCxwt("0");
        }
        if ("91".equals(ryzt))//待解聘异常
        {
            ryxx.setRyZt("9");
            ryxx.setRyZycgrq(StringUtils.isEmpty(request.getParameter("ry_zycgrq")) ? null : new DateTime(request.getParameter("ry_zycgrq")).toDate());
            ryxx.setRyXzjsj(StringUtils.isEmpty(request.getParameter("ry_xzjsj")) ? null : new DateTime(request.getParameter("ry_xzjsj")).toDate());
            ryxx.setRyZzr(StringUtils.isEmpty(request.getParameter("ry_zzr")) ? null : new DateTime(request.getParameter("ry_zzr")).toDate());
            ryxx.setRyLzsj(StringUtils.isEmpty(request.getParameter("ry_lzsj")) ? null : new DateTime(request.getParameter("ry_lzsj")).toDate());
            ryxx.setRyLzyy(StrKits.emptyToStr(request.getParameter("ry_lzyy")));
            ryxx.setRyLzbz(StrKits.emptyToStr(request.getParameter("ry_lzbz")));
            ryxx.setRyLxqk(StrKits.emptyToStr(request.getParameter("ry_lxqk")));
            ryxx.setRyBllzqk(StrKits.emptyToStr(request.getParameter("ry_bllzqk")));
            ryxx.setRyJpsj(StringUtils.isEmpty(request.getParameter("ry_jpsj")) ? null : new DateTime(request.getParameter("ry_jpsj")).toDate());
            ryxx.setIsDjp("1");
            ryxx.setIsCxwt("0");
        }
        if ("9".equals(ryzt))//异常状态
        {
            ryxx.setRyZt("9");
            ryxx.setRyZycgrq(StringUtils.isEmpty(request.getParameter("ry_zycgrq")) ? null : new DateTime(request.getParameter("ry_zycgrq")).toDate());
            ryxx.setRyXzjsj(StringUtils.isEmpty(request.getParameter("ry_xzjsj")) ? null : new DateTime(request.getParameter("ry_xzjsj")).toDate());
            ryxx.setRyZzr(StringUtils.isEmpty(request.getParameter("ry_zzr")) ? null : new DateTime(request.getParameter("ry_zzr")).toDate());
            ryxx.setRyLzsj(StringUtils.isEmpty(request.getParameter("ry_lzsj")) ? null : new DateTime(request.getParameter("ry_lzsj")).toDate());
            ryxx.setRyLzyy(StrKits.emptyToStr(request.getParameter("ry_lzyy")));
            ryxx.setRyLzbz(StrKits.emptyToStr(request.getParameter("ry_lzbz")));
            ryxx.setRyLxqk(StrKits.emptyToStr(request.getParameter("ry_lxqk")));
            ryxx.setRyBllzqk(StrKits.emptyToStr(request.getParameter("ry_bllzqk")));
            ryxx.setRyJpsj(null);
            ryxx.setIsDjp("0");
            ryxx.setIsCxwt("0");
        }
    }

    @Log(module = "人员信息", desc = "删除")
    @Override
    @Transactional
    public Response deleteSave(HttpServletRequest request, String czr) {
        String ids = StrKits.emptyToStr(request.getParameter("id"));
        List<String> idList = Lists.newArrayList(ids.split(","));
        TbRsdlRyxx ryxx = null;
        for (String ryid : idList) {
            ryxx = new TbRsdlRyxx();
            ryxx.setRyId(ryid);
            ryxx.setXgr(czr);
            ryxx.setXgsj(new Date());
            ryxx.setRyZt("0");
            if (this.baseMapper.updateById(ryxx) < 0) {
                throw new RsdpSystemException(StatusCode.OPER_FAILED.getCode(), i18n.getMessage(StatusCode.OPER_FAILED.getKey()));
            }
        }
        return new Response(StatusCode.SUCCESS.getCode(), i18n.getMessage(StatusCode.SUCCESS.getKey()));
    }

    @Log(module = "人员信息", desc = "撤销委托")
    @Override
    @Transactional
    public Response cxwtSave(HttpServletRequest request, String czr) {
        String ids = StrKits.emptyToStr(request.getParameter("id"));
        List<String> idList = Lists.newArrayList(ids.split(","));
        TbRsdlRyxx ryxx = null;
        Date now = new Date();
        for (String ryid : idList) {
            ryxx = new TbRsdlRyxx();
            ryxx.setRyId(ryid);
            ryxx.setRyZzr(now);
            ryxx.setRyLzsj(now);
            ryxx.setIsCxwt("1");
            ryxx.setIsCxwt("0");
            ryxx.setXgr(czr);
            ryxx.setXgsj(new Date());
            ryxx.setRyZt("3");
            if (this.baseMapper.updateById(ryxx) < 0) {
                throw new RsdpSystemException(StatusCode.OPER_FAILED.getCode(), i18n.getMessage(StatusCode.OPER_FAILED.getKey()));
            }
        }
        return new Response(StatusCode.SUCCESS.getCode(), i18n.getMessage(StatusCode.SUCCESS.getKey()));
    }

    @Override
    public Response checkRyxm(HttpServletRequest request) {
        Wrapper wrapper = Condition.create()
                .eq("GS_ID", StrKits.emptyToStr(request.getParameter("gsid")))
                .eq("GSB_ID", StrKits.emptyToStr(request.getParameter("xgsid")))
                .eq("RY_XM", StrKits.emptyToStr(request.getParameter("xm")))
                .eq("RY_ZJHM", StrKits.emptyToStr(request.getParameter("sfzhm")))
                .eq("RY_ZJLX", StrKits.emptyToStr(request.getParameter("zjlx")));
        
        if (!"4".equals(StrKits.emptyToStr(request.getParameter("ryzt")))) {
            wrapper.eq("RY_ZT", StrKits.emptyToStr(request.getParameter("ryzt")));
        }
        else
        {
        		//如果人员状态为解聘 直接通过验证
        		return new Response(StatusCode.SUCCESS.getCode(), i18n.getMessage(StatusCode.SUCCESS.getKey()));
        }
        if (StringUtils.isNotEmpty(request.getParameter("id"))) {
            wrapper.ne("RY_ID", StrKits.emptyToStr(request.getParameter("id")));
        }
        if (this.baseMapper.selectCount(wrapper) > 0) {
            throw new RsdpSystemException(RyStatusCode.RY_FOUND.getCode(), i18n.getMessage(RyStatusCode.RY_FOUND.getKey()));
        }
        return new Response(StatusCode.SUCCESS.getCode(), i18n.getMessage(StatusCode.SUCCESS.getKey()));
    }

    @Log(module = "人员信息", desc = "离职")
    @Override
    public Response rylzSave(HttpServletRequest request, String czr) {
        String ids = StrKits.emptyToStr(request.getParameter("hid_id"));
        List<String> idList = Lists.newArrayList(ids.split(","));
        TbRsdlRyxx ryxx = null;
        for (String ryid : idList) {
            ryxx = this.baseMapper.selectById(ryid);
            if (ryxx == null || ryxx.getRyZt().equals("0") || ryxx.getRyZt().equals("1") || ryxx.getRyZt().equals("3") || ryxx.getRyZt().equals("4") || ryxx.getRyZt().equals("9")) {
                continue;
            } else {
                ryxx.setRyZt("3");
                ryxx.setXgr(czr);
                ryxx.setXgsj(new Date());
                ryxx.setRyZzr(StringUtils.isEmpty(request.getParameter("ry_lzsj")) ? null : new DateTime(request.getParameter("ry_lzsj")).toDate());
                ryxx.setRyLzsj(StringUtils.isEmpty(request.getParameter("ry_lzsj")) ? null : new DateTime(request.getParameter("ry_lzsj")).toDate());
                ryxx.setRyLzyy(StrKits.emptyToStr(request.getParameter("ry_lzyy")));
                ryxx.setRyLzbz(StrKits.emptyToStr(request.getParameter("ry_lzbz")));
                if (this.baseMapper.updateById(ryxx) < 0) {
                    throw new RsdpSystemException(StatusCode.OPER_FAILED.getCode(), i18n.getMessage(StatusCode.OPER_FAILED.getKey()));
                }
            }
        }
        return new Response(StatusCode.SUCCESS.getCode(), i18n.getMessage(StatusCode.SUCCESS.getKey()));
    }

    @Override
    public List<HashMap> getRyxxListExport(HttpServletRequest request, String czr, String lx) {
        String gsmc = StrKits.emptyToStr(request.getParameter("gsmc"));
        String xgsmc = StrKits.emptyToStr(request.getParameter("xgsmc"));
        String lrr = StrKits.emptyToStr(request.getParameter("lrr"));
        String xm = StrKits.emptyToStr(request.getParameter("xm"));
        String ryzt = StrKits.emptyToStr(request.getParameter("ryzt"));
        String sfzhm = StrKits.emptyToStr(request.getParameter("sfzhm"));
        String dnh = StrKits.emptyToStr(request.getParameter("dnh"));
        String khbh = StrKits.emptyToStr(request.getParameter("khbh"));
        String cxrqq = StrKits.emptyToStr(request.getParameter("cxrqq"));
        String cxrqz = StringUtils.isEmpty(request.getParameter("cxrqz")) ? "" : request.getParameter("cxrqz") + " 23:59:59";
        String sort = StrKits.emptyToStr(request.getParameter("sort"));
        String order = StrKits.emptyToStr(request.getParameter("order"));
        String lzyy = StrKits.emptyToStr(request.getParameter("lzyy"));
        String yc = StrKits.emptyToStr(request.getParameter("yc"));
        String lxqk = StrKits.emptyToStr(request.getParameter("lxqk"));

        return this.baseMapper.getRyListExport(lrr, lx, gsmc, xgsmc, xm, ryzt, sfzhm, dnh, khbh, cxrqq, cxrqz,lzyy,yc,lxqk, czr, StrKits.getOrderBy(sort, order));
    }

    @Log(module = "人员信息", desc = "人员信息导出")
    @Override
    public Workbook ryListExcelExport(HttpServletRequest request, String czr, String lx) {
        List<HashMap> list = this.getRyxxListExport(request, czr, lx);

        Workbook wb = new HSSFWorkbook();
        Sheet sheet = wb.createSheet("员工信息");
        Row row = null;
        Cell cell = null;
        int rowIndex = 0;

        //自动列宽
        for (int i = 0; i < 61; i++) {
            sheet.setColumnWidth(i, 5000);
        }
        //创建字体
        HSSFFont headFont = (HSSFFont) wb.createFont();
        headFont.setFontHeightInPoints((short) 13);//设置字体大小
        //headFont.setBold(true);

        HSSFFont contFont = (HSSFFont) wb.createFont();
        contFont.setFontHeightInPoints((short) 12);//设置字体大小

        HSSFCellStyle headStyle = (HSSFCellStyle) wb.createCellStyle();
        headStyle.setFont(headFont);
        //headStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        //headStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.ORANGE.getIndex());
        headStyle.setBorderBottom(BorderStyle.THIN); //下边框
        headStyle.setBorderLeft(BorderStyle.THIN);//左边框
        headStyle.setBorderTop(BorderStyle.THIN);//上边框
        headStyle.setBorderRight(BorderStyle.THIN);//右边框
        headStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
        headStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直集中

        HSSFCellStyle contStyle = (HSSFCellStyle) wb.createCellStyle();
        contStyle.setFont(contFont);
        contStyle.setBorderBottom(BorderStyle.THIN); //下边框
        contStyle.setBorderLeft(BorderStyle.THIN);//左边框
        contStyle.setBorderTop(BorderStyle.THIN);//上边框
        contStyle.setBorderRight(BorderStyle.THIN);//右边框
        contStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
        contStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直集中

        row = sheet.createRow(rowIndex++);
        row.setHeight((short) 500);//行高

        //创建表头
        createRyCellHead(headStyle, row);

        //填充数据
        createRyRow(rowIndex, contStyle, sheet, list);
        return wb;
    }

    @Log(module = "人员信息", desc = "增员")
    @Override
    public Response wbSave(HttpServletRequest request, String czr) {
        String ryid = StrKits.emptyToStr(request.getParameter("hid_id"));
        TbRsdlRyxx ryxx = this.baseMapper.selectById(ryid);
        if (ryxx == null) {
            throw new RsdpSystemException(RyStatusCode.RY_NOTFOUND.getCode(), i18n.getMessage(RyStatusCode.RY_NOTFOUND.getKey()));
        }
        ryxx.setGsId(StrKits.emptyToStr(request.getParameter("sel_gs")));
        ryxx.setGsbId(StrKits.emptyToStr(request.getParameter("sel_xgs")));
        ryxx.setRyXm(StrKits.emptyToStr(request.getParameter("ry_xm")));
        ryxx.setRyZjlx(StrKits.emptyToStr(request.getParameter("sel_zjlx")));
        ryxx.setRyZjhm(StrKits.emptyToStr(request.getParameter("ry_zjhm")));
        ryxx.setRyLxfs(StrKits.emptyToStr(request.getParameter("ry_lxfs")));
        ryxx.setRyKhbh(StrKits.emptyToStr(request.getParameter("ry_khbh")));
        ryxx.setRyPqdl(StrKits.emptyToStr(request.getParameter("sel_pqdlfs")));
        ryxx.setRyBrsf(StrKits.emptyToStr(request.getParameter("ry_brsf")));
        ryxx.setRyDnh(StrKits.emptyToStr(request.getParameter("ry_dnh")));
        ryxx.setRyQsr(StringUtils.isEmpty(request.getParameter("ry_qsr")) ? null : new DateTime(request.getParameter("ry_qsr")).toDate());
        ryxx.setRyXdsj(StringUtils.isEmpty(request.getParameter("ry_xdsj")) ? null : new DateTime(request.getParameter("ry_xdsj")).toDate());
        ryxx.setRySbh(StrKits.emptyToStr(request.getParameter("ry_sbh")));
        ryxx.setRyGjjh(StrKits.emptyToStr(request.getParameter("ry_gjjh")));
        ryxx.setSbjndDm(StrKits.emptyToStr(request.getParameter("sel_sbjnd")));
        ryxx.setGjjjndDm(StrKits.emptyToStr(request.getParameter("sel_gjjjnd")));
        ryxx.setSbjnzhDm(StrKits.emptyToStr(request.getParameter("sel_sbzh")));
        ryxx.setGjjzhDm(StrKits.emptyToStr(request.getParameter("sel_gjjzh")));
        ryxx.setRySfkgsb(StrKits.emptyToStr(request.getParameter("ry_sfkgsb")));
        ryxx.setRySfkggjj(StrKits.emptyToStr(request.getParameter("ry_sfkggjj")));
        ryxx.setRyFwfjn(StrKits.emptyToStr(request.getParameter("ry_fwfjn")));
        ryxx.setRyGjjsfgw(StrKits.emptyToStr(request.getParameter("ry_gjjsfkgw")));
        ryxx.setRySbfsfgw(StrKits.emptyToStr(request.getParameter("ry_sbfsfkgw")));
        ryxx.setGzNdsb(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_ndsb"), "0")));
        ryxx.setGzNdgjj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_ndgjj"), "0")));
        ryxx.setGzSndsb(ryxx.getGzNdsb());
        ryxx.setGzSndgjj(ryxx.getGzNdgjj());
        ryxx.setGzGrbl(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_grbl"), "0")));
        ryxx.setGzGsbl(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_gsbl"), "0")));
        ryxx.setGzGrjn(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_grjn"), "0")));
        ryxx.setGzGsjn(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_gsjn"), "0")));
        ryxx.setGzSbjnhj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_sbjnhj"), "0")));
        ryxx.setSbbz(StrKits.emptyToStr(request.getParameter("gz_sbbz")));
        ryxx.setGjjbz(StrKits.emptyToStr(request.getParameter("gz_gjjbz")));
        ryxx.setGzFwf(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_fwf"), "0")));
        ryxx.setGzDaf(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_daf"), "0")));
        ryxx.setGzRsbz(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_rsbz"), "0")));
        ryxx.setGzMzyl(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_mzyl"), "0")));
        ryxx.setGzTj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_tj"), "0")));
        ryxx.setGzZdjb(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_zdjb"), "0")));
        ryxx.setGzZybt(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_zybt"), "0")));
        ryxx.setGzZnmz(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_znmz"), "0")));
        ryxx.setGzZnyw(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_znyw"), "0")));
        ryxx.setGzJc(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_jc"), "0")));
        ryxx.setGzSr(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_sr"), "0")));
        ryxx.setGzHd(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_hd"), "0")));
        ryxx.setGzQnf(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_qnf"), "0")));
        ryxx.setGzXcsj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_xcsj"), "0")));
        ryxx.setGzQt1(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_qt1"), "0")));
        ryxx.setGzQt1bz(StrKits.emptyToStr(request.getParameter("gz_qt1bz")));
        ryxx.setGzSj(new BigDecimal(StrKits.emptyToStrDefault(request.getParameter("gz_sj"), "0")));
        ryxx.setBz(StrKits.emptyToStr(request.getParameter("ry_bz")));
        ryxx.setXgr(czr);
        ryxx.setXgsj(new Date());
        ryxx.setRyZt("2");
        ryxx.setDlr(StrKits.emptyToStr(request.getParameter("sel_dlr")));
        ryxx.setRyZycgrq(StringUtils.isEmpty(request.getParameter("ry_zycgrq")) ? null : new DateTime(request.getParameter("ry_zycgrq")).toDate());
        ryxx.setRyXzjsj(StringUtils.isEmpty(request.getParameter("ry_xzjsj")) ? null : new DateTime(request.getParameter("ry_xzjsj")).toDate());

        if (this.baseMapper.updateAllColumnById(ryxx) > 0) {
            return new Response(StatusCode.SUCCESS.getCode(), i18n.getMessage(StatusCode.SUCCESS.getKey()));
        } else {
            return new Response(StatusCode.OPER_FAILED.getCode(), i18n.getMessage(StatusCode.OPER_FAILED.getKey()));
        }
    }

    @Log(module = "待办任务", desc = "人员解聘")
    @Override
    @Transactional
    public Response ryjpSave(HttpServletRequest request, String czr) {
        String ids = StrKits.emptyToStr(request.getParameter("id"));
        List<String> idList = Lists.newArrayList(ids.split(","));
        TbRsdlRyxx ryxx = null;
        for (String ryid : idList) {
            ryxx = new TbRsdlRyxx();
            ryxx.setRyId(ryid);
            ryxx.setXgr(czr);
            ryxx.setXgsj(new Date());
            ryxx.setRyZt("4");
            ryxx.setIsDjp("0");
            ryxx.setIsCxwt("0");
            ryxx.setRyJpsj(new Date());
            if (this.baseMapper.updateById(ryxx) < 0) {
                throw new RsdpSystemException(StatusCode.OPER_FAILED.getCode(), i18n.getMessage(StatusCode.OPER_FAILED.getKey()));
            }

        }
        return new Response(StatusCode.SUCCESS.getCode(), i18n.getMessage(StatusCode.SUCCESS.getKey()));
    }

    @Log(module = "待办任务", desc = "人员异常")
    @Override
    @Transactional
    public Response ryycSave(HttpServletRequest request, String czr,String type) {
        String ids = StrKits.emptyToStr(request.getParameter("id"));
        List<String> idList = Lists.newArrayList(ids.split(","));
        TbRsdlRyxx ryxx = null;
        for (String ryid : idList) {
            ryxx = new TbRsdlRyxx();
            ryxx.setRyId(ryid);
            ryxx.setXgr(czr);
            ryxx.setXgsj(new Date());
            if("0".equals(type)){
                ryxx.setRyZt("9");
                ryxx.setIsDjp("0");
                ryxx.setIsCxwt("0");
            }
            else
            {
                ryxx.setRyZt("9");
                ryxx.setIsDjp("1");
                ryxx.setIsCxwt("0");
            }
            if (this.baseMapper.updateById(ryxx) < 0) {
                throw new RsdpSystemException(StatusCode.OPER_FAILED.getCode(), i18n.getMessage(StatusCode.OPER_FAILED.getKey()));
            }
        }
        return new Response(StatusCode.SUCCESS.getCode(), i18n.getMessage(StatusCode.SUCCESS.getKey()));
    }

    @Log(module = "待办任务", desc = "人员待解聘")
    @Override
    @Transactional
    public Response ryDjpSave(HttpServletRequest request, String czr) {
        String ids = StrKits.emptyToStr(request.getParameter("id"));
        List<String> idList = Lists.newArrayList(ids.split(","));
        TbRsdlRyxx ryxx = null;
        for (String ryid : idList) {
            ryxx = this.baseMapper.selectById(ryid);

            if ("3".equals(ryxx.getRyZt())) {
                ryxx.setXgr(czr);
                ryxx.setXgsj(new Date());
                ryxx.setRyZt("4");
                ryxx.setIsDjp("1");
                ryxx.setIsCxwt("0");
                if (this.baseMapper.updateAllColumnById(ryxx) < 0) {
                    throw new RsdpSystemException(StatusCode.OPER_FAILED.getCode(), i18n.getMessage(StatusCode.OPER_FAILED.getKey()));
                }
            }
        }
        return new Response(StatusCode.SUCCESS.getCode(), i18n.getMessage(StatusCode.SUCCESS.getKey()));
    }

    @Log(module = "人员信息", desc = "人员信息模板导入")
    @Transactional
    @Override
    public Response ryxxImportSave(MultipartFile file, TbUser user, boolean isManager) {
        if (file == null)//文件为空
        {
            throw new RsdpSystemException(ExcelStatusCode.XLS_EMPTY.getCode(), i18n.getMessage(ExcelStatusCode.XLS_EMPTY.getKey()));
        }
        InputStream is = null;
        Workbook wb = null;
        Sheet sheet = null;
        Row row = null;
        List<Row> data = new ArrayList<Row>();
        List<String> errList = new ArrayList<String>();
        Cell cell = null;
        try {
            is = file.getInputStream();
            wb = new HSSFWorkbook(is);

            if (wb.getNumberOfSheets() == 0)//模板必须要有一个sheet表
            {
                throw new RsdpSystemException(ExcelStatusCode.XLS_NOTFORMATED.getCode(), i18n.getMessage(ExcelStatusCode.XLS_NOTFORMATED.getKey()));
            }
            //读取excel文件
            sheet = wb.getSheetAt(0);//读取第一个sheet表
            int rowCount = sheet.getLastRowNum();//获取模板总数
            logger.debug("ryxx importSave row count:{}", rowCount);
            if (rowCount < 1)//空数据
            {
                throw new RsdpSystemException(ExcelStatusCode.XLS_DATAEMPTY.getCode(), i18n.getMessage(ExcelStatusCode.XLS_DATAEMPTY.getKey()));
            }
            Iterator<Row> it = sheet.iterator();
            int rowNo = 0;
            int cellCount = 0;
            CellKey cellKey = null;
            List<HashMap> zjlxList = dicMapper.getDicListByFl("证件类型");//获取证件类型列表
            Map<String, String> zjlxMap = new HashMap<String, String>();//定义证件类型缓存
            //循环读取数据
            while (it.hasNext()) {
                row = it.next();

                if (row != null && row.getRowNum() > 0) {
                    rowNo = row.getRowNum();
                    //logger.debug("tzxx importSave check rowNo:{}", rowNo);
                    //设置单元格为字符串类型
                    for (int i = 0; i < 61; i++) {
                        excel.setStringCell(row.getCell(i));
                        cellKey = COLUMN_IMPORT.get(i);
                        if (!"9".equals(cellKey.getType())) {
                            excel.checkCellValue(rowNo+1, i, cellKey, row.getCell(i), errList);
                        }
                        
                        if (i == 7)//证件类型校验
                        {
                            if (row.getCell(i) != null && StringUtils.isNotEmpty(row.getCell(i).getStringCellValue())) {
                                if(StringUtils.isEmpty(getZjlxListId(row.getCell(i), zjlxList, zjlxMap))) {
                                		errList.add(i18n.getMessage(RyStatusCode.RY_ZJLXERROR.getKey(), new Object[]{(rowNo+1)+"", i + 1, cellKey.getHead()}));
                                }
                            }
                        }
                        if (i == 8)//身份证号码校验
                        {
                            if (row.getCell(i) != null && StringUtils.isNotEmpty(row.getCell(i).getStringCellValue())&&"201".equals(row.getCell(i).getStringCellValue())) {
                                if (!IdCardKits.isValidatedAllIdcard(row.getCell(i).getStringCellValue())) {
                                    errList.add(i18n.getMessage(RyStatusCode.RY_SFZHMERROR.getKey(), new Object[]{(rowNo+1)+"", i + 1, cellKey.getHead()}));
                                }
                            }
                        }
                    }
                    if (errList.size() > 0) {
                        if (!data.isEmpty()) {
                            data.clear();
                        }
                    } else {
                        data.add(row);
                    }
                }
            }

        } catch (IOException e) {
            logger.error("ryxx importSave error:{}", e.getMessage());
            throw new RsdpSystemException(StatusCode.SERVER_ERROR.getCode(), e.getMessage());
        } finally {
            try {
                //关闭流及文件
                wb.close();
                is.close();
            } catch (IOException e) {
                logger.error("ryxx importSave close error:{}", e.getMessage());
            }
        }
        int count = 0;//记录保存成功数量
        if (errList.size() > 0)//模板校验错误直接抛出
        {
            return new Response(ExcelStatusCode.XLS_ERROR.getCode(), i18n.getMessage(ExcelStatusCode.XLS_ERROR.getKey(), new Object[]{Joiner.on("").join(errList)}));
        } else {
            logger.debug("tzxx importSave dataList:{}", data);
            String czr = user.getUserId();
            List<HashMap> gsList = gsMapper.getGsAll();//获取公司列表
            List<HashMap> xgsList = xgsMapper.getXgsAll();//获取小公司列表
            List<HashMap> ryList = this.baseMapper.getRyxxByCzr(czr);//获取操作人人员列表
            List<HashMap> czrList = czrMapper.getUserAll("");//获取用户列表
            List<HashMap> pqdlfsList = dicMapper.getDicListByFl("派遣代理");//获取派遣代理列表
            List<HashMap> sbjnzhList = zhMapper.getZhListByType("01");//获取社保缴纳账户列表
            List<HashMap> sbjndList = dicMapper.getDicListByFl("社保缴纳地");//获取社保缴纳地列表
            List<HashMap> gjjjnzhList = zhMapper.getZhListByType("02");//获取公积金缴纳账户列表
            List<HashMap> gjjJndList = dicMapper.getDicListByFl("公积金缴纳地");//获取公积金缴纳地列表

            String gsid = "";
            String xgsid = "";
            String ryid = "";
            String lrr = user.getUserId();
            String dlr = "";
            String sbjnd = "";
            String gjjjnd = "";
            String sbjnzh = "";
            String gjjjnzh = "";
            String pqdlfs = "";
            String plId = StrKits.uuid();

            //定义的缓存对象
            Map<String, String> gsMap = new HashMap<String, String>();
            Map<String, String> xgsMap = new HashMap<String, String>();
            Map<String, String> czrMap = new HashMap<String, String>();
            Map<String, String> sbjndMap = new HashMap<String, String>();
            Map<String, String> sbjnzhMap = new HashMap<String, String>();
            Map<String, String> gjjjndMap = new HashMap<String, String>();
            Map<String, String> gjjjnzhMap = new HashMap<String, String>();
            Map<String, String> ryMap = new HashMap<String, String>();

            for (Row tr : data) {
                //如果非业务经理角色人员只能上传自己的数据调整记录
                /*if (!StringUtils.isEmpty(czr) && (!user.getUserGh().equals(tr.getCell(0).getStringCellValue()))) {
                    logger.debug("ryxx importSave Non self record skip!");
                    continue;
                }*/

                //负责人
                dlr = getLrrListId(tr.getCell(0).getStringCellValue().trim(), czrList, czrMap);

                if (StringUtils.isEmpty(dlr))//lrr为空 直接跳过
                {
                    logger.debug("ryxx importSave userid:{} lrr is empty record skip!", tr.getCell(0).getStringCellValue().trim());
                    continue;
                }

                //获取公司代码
                gsid = getGsListId(tr.getCell(4).getStringCellValue().trim(), gsList, gsMap);
                if (StringUtils.isEmpty(gsid))//gsid为空 直接跳过
                {
                    logger.debug("ryxx importSave gsmc:{} gsid is empty record skip!", tr.getCell(4).getStringCellValue().trim());
                    continue;
                }
                //logger.debug("ryxx importSave getXgsListId before xgsmc:{}!", tr.getCell(5).getStringCellValue());
                xgsid = getXgsListId(gsid, tr.getCell(5).getStringCellValue().trim(), xgsList, xgsMap);
                if (StringUtils.isEmpty(xgsid))//xgsid为空 直接跳过
                {
                    logger.debug("ryxx importSave xgsmc:{} xgsid is empty record skip!", tr.getCell(5).getStringCellValue().trim());
                    continue;
                }
                //获取员工信息
                ryid = getRyListId(gsid, xgsid, tr.getCell(6), tr.getCell(7), tr.getCell(8), ryList, ryMap);
                if (StringUtils.isNotEmpty(ryid))//ryid不为空 标识人员已存在 直接跳过
                {
                    logger.debug("ryxx importSave ryxx duplicate skip!");
                    continue;
                }
                //logger.debug("ryMap:{}",ryMap);
                //派遣代理方式
                pqdlfs = getPqdlfsListId(tr.getCell(12), pqdlfsList);
                //社保缴纳地
                sbjnd = getDicZhListDm(tr.getCell(2), sbjndList, sbjndMap, "sbjnd");
                //公积金缴纳地
                gjjjnd = getDicZhListDm(tr.getCell(3), gjjJndList, gjjjndMap, "gjjjnd");
                //社保账户
                sbjnzh = getDicZhListDm(tr.getCell(27), sbjnzhList, sbjnzhMap, "sbjnzh");
                //公积金账户
                gjjjnzh = getDicZhListDm(tr.getCell(30), gjjjnzhList, gjjjnzhMap, "gjjjnzh");

                TbRsdlRyxx ryxx = new TbRsdlRyxx();
                ryxx.setRyId(StrKits.uuid());
                ryxx.setPlBs(plId);
                ryxx.setBclxDm("1");
                ryxx.setLrr(czr);
                ryxx.setXgr(czr);
                ryxx.setDlr(dlr);

                ryxx.setSbjndDm(sbjnd);
                ryxx.setGjjjndDm(gjjjnd);
                ryxx.setGsId(gsid);
                ryxx.setGsbId(xgsid);
                ryxx.setRyXm(tr.getCell(6).getStringCellValue());
                ryxx.setRyZjlx(tr.getCell(7).getStringCellValue());
                ryxx.setRyZjhm(tr.getCell(8).getStringCellValue());
                ryxx.setRyLxfs(excel.getCellValue(tr.getCell(9)));
                ryxx.setRyDnh(excel.getCellValue(tr.getCell(10)));
                ryxx.setRyKhbh(excel.getCellValue(tr.getCell(11)));
                ryxx.setRyPqdl(pqdlfs);
                ryxx.setRyBrsf(excel.getCellValue(tr.getCell(13)));
                ryxx.setRySbh(excel.getCellValue(tr.getCell(14)));
                ryxx.setRyGjjh(excel.getCellValue(tr.getCell(15)));
                ryxx.setRyQsr(excel.getDateCellValue(tr.getCell(16)));
                ryxx.setRyZzr(excel.getDateCellValue(tr.getCell(17)));
                ryxx.setRyXdsj(excel.getDateCellValue(tr.getCell(18)));
                ryxx.setRyZycgrq(excel.getDateCellValue(tr.getCell(19)));
                ryxx.setRyXzjsj(excel.getDateCellValue(tr.getCell(20)));
                ryxx.setRyLzsj(excel.getDateCellValue(tr.getCell(21)));
                ryxx.setRyLzyy(excel.getCellValue(tr.getCell(22)));
                ryxx.setRyLxqk(excel.getCellValue(tr.getCell(23)));
                ryxx.setRyBllzqk(excel.getCellValue(tr.getCell(24)));
                ryxx.setRyJpsj(excel.getDateCellValue(tr.getCell(26)));
                ryxx.setSbjnzhDm(sbjnzh);
                ryxx.setRySfkgsb(excel.getCellValue(tr.getCell(28)));
                ryxx.setRySbfsfgw(excel.getCellValue(tr.getCell(29)));
                ryxx.setGjjzhDm(gjjjnzh);
                ryxx.setRySfkggjj(excel.getCellValue(tr.getCell(31)));
                ryxx.setRyGjjsfgw(excel.getCellValue(tr.getCell(32)));
                ryxx.setRyFwfjn(excel.getCellValue(tr.getCell(33)));
                ryxx.setBz(excel.getCellValue(tr.getCell(34)));

                ryxx.setGzNdsb(new BigDecimal(excel.getCellValue(tr.getCell(35), "0")));
                ryxx.setSbbz(excel.getCellValue(tr.getCell(36)));
                ryxx.setGzNdgjj(new BigDecimal(excel.getCellValue(tr.getCell(37), "0")));
                ryxx.setGzSndsb(ryxx.getGzNdsb());
                ryxx.setGzSndgjj(ryxx.getGzNdgjj());
                ryxx.setGzGsbl(new BigDecimal(excel.getCellValue(tr.getCell(38), "0")));
                ryxx.setGzGrbl(new BigDecimal(excel.getCellValue(tr.getCell(39), "0")));
                ryxx.setGzGsjn(new BigDecimal(excel.getCellValue(tr.getCell(40), "0")));
                ryxx.setGzGrjn(new BigDecimal(excel.getCellValue(tr.getCell(41), "0")));
                ryxx.setGzSbjnhj(new BigDecimal(excel.getCellValue(tr.getCell(42), "0")));
                ryxx.setGjjbz(excel.getCellValue(tr.getCell(43)));
                ryxx.setGzFwf(new BigDecimal(excel.getCellValue(tr.getCell(44), "0")));
                ryxx.setGzDaf(new BigDecimal(excel.getCellValue(tr.getCell(45), "0")));
                ryxx.setGzRsbz(new BigDecimal(excel.getCellValue(tr.getCell(46), "0")));
                ryxx.setGzMzyl(new BigDecimal(excel.getCellValue(tr.getCell(47), "0")));
                ryxx.setGzTj(new BigDecimal(excel.getCellValue(tr.getCell(48), "0")));
                ryxx.setGzZdjb(new BigDecimal(excel.getCellValue(tr.getCell(49), "0")));
                ryxx.setGzZybt(new BigDecimal(excel.getCellValue(tr.getCell(50), "0")));
                ryxx.setGzZnmz(new BigDecimal(excel.getCellValue(tr.getCell(51), "0")));
                ryxx.setGzZnyw(new BigDecimal(excel.getCellValue(tr.getCell(52), "0")));
                ryxx.setGzJc(new BigDecimal(excel.getCellValue(tr.getCell(53), "0")));
                ryxx.setGzSr(new BigDecimal(excel.getCellValue(tr.getCell(54), "0")));
                ryxx.setGzHd(new BigDecimal(excel.getCellValue(tr.getCell(55), "0")));
                ryxx.setGzQnf(new BigDecimal(excel.getCellValue(tr.getCell(56), "0")));
                ryxx.setGzXcsj(new BigDecimal(excel.getCellValue(tr.getCell(57), "0")));
                ryxx.setGzQt1(new BigDecimal(excel.getCellValue(tr.getCell(58), "0")));
                ryxx.setGzQt1bz(excel.getCellValue(tr.getCell(59)));
                ryxx.setGzSj(new BigDecimal(excel.getCellValue(tr.getCell(60), "0")));
                ryxx.setRyZt("1");
                //判断状态
                if (ryxx.getRyZycgrq() != null) {
                    ryxx.setRyZt("2");
                }
                if (ryxx.getRyLzsj() != null && ryxx.getRyJpsj() == null) {
                    ryxx.setRyZt("3");
                }
                if (ryxx.getRyLzsj() != null && ryxx.getRyJpsj() != null) {
                    ryxx.setRyZt("4");
                }
                if (this.baseMapper.insert(ryxx) < 0) {
                    return new Response(StatusCode.OPER_FAILED.getCode(), i18n.getMessage(StatusCode.OPER_FAILED.getKey()));
                }
                count++;
                gsid = "";
                xgsid = "";
                ryid = "";
                lrr = "";
                sbjnd = "";
                gjjjnd = "";
                sbjnzh = "";
                gjjjnzh = "";
                pqdlfs = "";
            }
        }
        logger.debug("ryxx importSave insert success:{}", count);

        return new Response(StatusCode.SUCCESS.getCode(), i18n.getMessage(ExcelStatusCode.XLS_SUCCESS.getKey(), new Object[]{count}));
    }

    private String getZjlxListId(Cell zjlx, List<HashMap> list, Map<String, String> zjlxMap) {
        //判断证件类型是否存在缓存map中 如果存在返回对应值
        if (StringUtils.isNotEmpty(zjlxMap.get(zjlx.getStringCellValue()))) {
            return zjlxMap.get(zjlx.getStringCellValue());
        }
        for (HashMap map : list) {
            if (zjlx.getStringCellValue().equals(map.get("DM"))) {
            		zjlxMap.put(zjlx.getStringCellValue(), zjlx.getStringCellValue());
                return zjlx.getStringCellValue();
            }
        }
        return "";
    }

    private String getRyListId(String gsid, String xgsid, Cell rymc,Cell zjlx, Cell zjhm, List<HashMap> list, Map<String, String> ryMap) {
        //判断公司id,小公司id,人员名称,证件号码是否存在缓存map中 如果存在返回对应值
        if (StringUtils.isNotEmpty(ryMap.get(gsid + xgsid + rymc.getStringCellValue()+ zjlx.getStringCellValue() + zjhm.getStringCellValue()))) {
            return ryMap.get(gsid + xgsid + rymc.getStringCellValue() + zjlx.getStringCellValue() + zjhm.getStringCellValue());
        }
        for (HashMap map : list) {
            if (rymc.getStringCellValue().equals(map.get("RY_XM")) && (map.get("RY_ZJHM").equals(zjhm.getStringCellValue())) && (map.get("RY_ZJLX").equals(zjlx.getStringCellValue())) && gsid.equals(map.get("GS_ID")) && xgsid.equals(map.get("GSB_ID"))) {
                ryMap.put(gsid + xgsid + rymc.getStringCellValue() + zjlx.getStringCellValue() + zjhm.getStringCellValue(), (String) map.get("RY_ID"));
                return Objects.toString(map.get("RY_ID"), "");
            }
        }
        ryMap.put(gsid + xgsid + rymc.getStringCellValue() + zjlx.getStringCellValue() + zjhm.getStringCellValue(), rymc.getStringCellValue());
        return "";
    }

    private String getLrrListId(String gh, List<HashMap> list, Map<String, String> czrMap) {
        if (StringUtils.isNotEmpty(czrMap.get(gh))) {
            return czrMap.get(gh);
        }
        for (HashMap map : list) {
            if (gh.equals(map.get("USER_GH"))) {
                czrMap.put(StrKits.emptyToStr(map.get("USER_GH")), StrKits.emptyToStr(map.get("USER_ID")));
                return Objects.toString(map.get("USER_ID"), "");
            }
        }
        return "";
    }

    private String getDicZhListDm(Cell cell, List<HashMap> list, Map<String, String> cacheMap, String type) {
        if (cell == null) {
            return "";
        }
        if (cell != null && StringUtils.isNotEmpty(cacheMap.get(type + cell.getStringCellValue()))) {
            return cacheMap.get(type + cell.getStringCellValue());
        }
        for (HashMap map : list) {
            if (cell.getStringCellValue().equals(map.get("MC"))) {
                cacheMap.put(type + cell.getStringCellValue(), StrKits.emptyToStr(map.get("DM")));
                return Objects.toString(map.get("DM"), "");
            }
        }
        return "";
    }

    private String getGsListId(String str, List<HashMap> list, Map<String, String> gsMap) {
        if (StringUtils.isNotEmpty(gsMap.get(str))) {
            return gsMap.get(str);
        }
        for (HashMap map : list) {
            //logger.debug("getGsListId:{}", map.get("GS_MC"));
            if (str.equals(map.get("GS_MC"))) {
                gsMap.put(str, StrKits.emptyToStr(map.get("GS_ID")));
                return Objects.toString(map.get("GS_ID"), "");
            }
        }
        return "";
    }

    private String getXgsListId(String gsid, String str, List<HashMap> list, Map<String, String> xgsMap) {
        //logger.debug("getXgsListId gsid:{} str:{}", gsid, str);
        if (StringUtils.isNotEmpty(xgsMap.get(gsid + str))) {
            return xgsMap.get(gsid + str);
        }
        for (HashMap map : list) {
            //logger.debug("xgsList gsbmc:{} gsid:{} check:{}", map.get("GSB_MC"), map.get("GS_ID"), str.equals(map.get("GSB_MC")) && gsid.equals(map.get("GS_ID")));
            if (str.equals(map.get("GSB_MC")) && gsid.equals(map.get("GS_ID"))) {
                xgsMap.put(gsid + str, StrKits.emptyToStr(map.get("GSB_ID")));
                return Objects.toString(map.get("GSB_ID"), "");
            }
        }
        return "";
    }

    private String getPqdlfsListId(Cell cell, List<HashMap> list) {

        if (cell == null || StringUtils.isEmpty(cell.getStringCellValue())) {
            return "";
        }
        for (HashMap map : list) {
            if (cell.getStringCellValue().equals(map.get("MC"))) {
                return Objects.toString(map.get("DM"), "");
            }
        }
        return "";
    }

    private void createRyCellHead(HSSFCellStyle headStyle, Row row) {
        int columnIndex = 0;
        Cell cell = null;
        for (CellKey column : COLUMN) {
            cell = row.createCell(columnIndex++);
            cell.setCellType(CellType.STRING);
            cell.setCellStyle(headStyle);
            cell.setCellValue(column.getHead());
        }
    }

    private void createRyRow(int rowIndex, HSSFCellStyle contStyle, Sheet sheet, List<HashMap> list) {
        int columnIndex = 0;
        Row row;
        for (HashMap map : list) {
            row = sheet.createRow(rowIndex++);
            row.setHeight((short) 500);//excel行高*20
            for (CellKey column : COLUMN) {
                createCell(contStyle, row.createCell(columnIndex++), column, map);
            }
            columnIndex = 0;
        }
    }

    private void createCell(HSSFCellStyle contStyle, Cell cell, CellKey column, Map map) {
        if ("1".equals(column.getType())) {
            cell.setCellType(CellType.STRING);
            cell.setCellStyle(contStyle);
            cell.setCellValue(StrKits.emptyToStr(map.get(column.getKey())));
        }
        if ("2".equals(column.getType())) {
            cell.setCellType(CellType.NUMERIC);
            cell.setCellStyle(contStyle);
            cell.setCellValue(StrKits.emptyToStr(map.get(column.getKey())));
        }
        if ("3".equals(column.getType())) {
            cell.setCellType(CellType.STRING);
            cell.setCellStyle(contStyle);
            cell.setCellValue(map.get(column.getKey()) == null ? "" : new DateTime(map.get(column.getKey())).toString("yyyy-MM-dd"));
        }
        if ("4".equals(column.getType())) {
            cell.setCellType(CellType.STRING);
            cell.setCellStyle(contStyle);
            cell.setCellValue(map.get(column.getKey()) == null ? "" : new DateTime(map.get(column.getKey())).toString("yyyy-MM-dd HH:mm:ss"));
        }
        if ("9".equals(column.getType())) {
            cell.setCellType(CellType.STRING);
            cell.setCellStyle(contStyle);
            cell.setCellValue(getRyZtMc(StrKits.emptyToStr(map.get(column.getKey()))));
        }
    }

	@Override
	public List<HashMap> getRyHistory(String ryId) {
		return baseMapper.getRyHistory(ryId);
	}

	@Override
	@Transactional
	public Response ryBgjsSave(HttpServletRequest request, String czr,String czrMc) {
		String ids = StrKits.emptyToStr(request.getParameter("hid_id"));
        List<String> idList = Lists.newArrayList(ids.split(","));
        TbRsdlRyxx ryxx = null;
        BigDecimal ndSb = null;
        BigDecimal ndGjj = null;
        int flag = 0;//未执行任何操作时为0
        for (String ryid : idList) {
            ryxx = this.baseMapper.selectById(ryid);
            if (ryxx == null || ryxx.getRyZt().equals("0")) {
                continue;
            } else {
            		ndSb = new BigDecimal(StrKits.emptyToStr(request.getParameter("gz_ndsb")));
            		ndGjj = new BigDecimal(StrKits.emptyToStr(request.getParameter("gz_ndgjj")));
            		//修改社保基数
            		if(ryxx.getGzNdsb().compareTo(ndSb)!=0) {
            			ryxx.setGzSndsb(ryxx.getGzNdsb());
            			ryxx.setGzNdsb(ndSb);
                		TbRsdlHistory history = new TbRsdlHistory();
                		history.setHisId(StrKits.uuid());
                		history.setObjId(ryid);
                		history.setHisType("01");
                		history.setXgr(czr);
                		history.setXgsj(new Date());
                		history.setHisCont(i18n.getMessage("his.sndsb", new Object[] {StrKits.getNowDateStr("yyyy年MM月dd日"),czrMc,ryxx.getGzSndsb().setScale(2,BigDecimal.ROUND_HALF_UP).toPlainString(),ryxx.getGzNdsb().setScale(2,BigDecimal.ROUND_HALF_UP).toPlainString()}));
                		historyMapper.insert(history);
                		flag++;
                }
            		//修改公积金基数
                if(ryxx.getGzNdgjj().compareTo(ndGjj)!=0) {
                		ryxx.setGzSndgjj(ryxx.getGzNdgjj());
	                	ryxx.setGzNdgjj(ndGjj);
	            		ryxx.setGzGrjn(ndGjj.multiply(ryxx.getGzGrbl()));
	            		ryxx.setGzGsjn(ndGjj.multiply(ryxx.getGzGsbl()));
	            		ryxx.setGzSbjnhj(ryxx.getGzGrjn().add(ryxx.getGzGsjn()));
                    TbRsdlHistory history = new TbRsdlHistory();
                    history.setHisId(StrKits.uuid());
                    history.setObjId(ryid);
                    history.setHisType("01");
                    history.setXgr(czr);
                    history.setXgsj(new Date());
                    history.setHisCont(i18n.getMessage("his.sndgjj", new Object[] {StrKits.getNowDateStr("yyyy年MM月dd日"),czrMc,ryxx.getGzSndgjj().setScale(2,BigDecimal.ROUND_HALF_UP).toPlainString(),ryxx.getGzNdgjj().setScale(2,BigDecimal.ROUND_HALF_UP).toPlainString()}));
                    historyMapper.insert(history);
                    flag++;
                }
                if(flag==0)
                {
                		continue;
                }
                ryxx.setXgr(czr);
                ryxx.setXgsj(new Date());
                if (this.baseMapper.updateById(ryxx) < 0) {
                    throw new RsdpSystemException(StatusCode.OPER_FAILED.getCode(), i18n.getMessage(StatusCode.OPER_FAILED.getKey()));
                }
            }
        }
        return new Response(StatusCode.SUCCESS.getCode(), i18n.getMessage(StatusCode.SUCCESS.getKey()));
	}

	@Override
	public DataGrid getRyxxJpList(Page<HashMap> page, HttpServletRequest request, String czr) {
		String gsmc = StrKits.emptyToStr(request.getParameter("gsmc"));
        String xgsmc = StrKits.emptyToStr(request.getParameter("xgsmc"));
        String lrr = StrKits.emptyToStr(request.getParameter("lrr"));
        String xm = StrKits.emptyToStr(request.getParameter("xm"));
        String ryzt = StrKits.emptyToStr(request.getParameter("ryzt"));
        String sfzhm = StrKits.emptyToStr(request.getParameter("sfzhm"));
        String cxrqq = StrKits.emptyToStr(request.getParameter("cxrqq"));
        String cxrqz = StringUtils.isEmpty(request.getParameter("cxrqz")) ? "" : request.getParameter("cxrqz") + " 23:59:59";
        String sort = StrKits.emptyToStr(request.getParameter("sort"));
        String order = StrKits.emptyToStr(request.getParameter("order"));

        page.setRecords(this.baseMapper.getRyxxJpList(page, lrr, gsmc, xgsmc, xm, ryzt, sfzhm, cxrqq, cxrqz, czr, StrKits.getOrderBy(sort, order)));
        return new DataGrid(page.getRecords(), page.getTotal());
	}

	@Override
	public Workbook ryjpListExcelExport(HttpServletRequest request, String czr) {
		List<HashMap> list = this.getRyxxJpListExport(request, czr);

        Workbook wb = new HSSFWorkbook();
        Sheet sheet = wb.createSheet("员工信息");
        Row row = null;
        Cell cell = null;
        int rowIndex = 0;

        //自动列宽
        for (int i = 0; i < 61; i++) {
            sheet.setColumnWidth(i, 5000);
        }
        //创建字体
        HSSFFont headFont = (HSSFFont) wb.createFont();
        headFont.setFontHeightInPoints((short) 13);//设置字体大小
        //headFont.setBold(true);

        HSSFFont contFont = (HSSFFont) wb.createFont();
        contFont.setFontHeightInPoints((short) 12);//设置字体大小

        HSSFCellStyle headStyle = (HSSFCellStyle) wb.createCellStyle();
        headStyle.setFont(headFont);
        //headStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        //headStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.ORANGE.getIndex());
        headStyle.setBorderBottom(BorderStyle.THIN); //下边框
        headStyle.setBorderLeft(BorderStyle.THIN);//左边框
        headStyle.setBorderTop(BorderStyle.THIN);//上边框
        headStyle.setBorderRight(BorderStyle.THIN);//右边框
        headStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
        headStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直集中

        HSSFCellStyle contStyle = (HSSFCellStyle) wb.createCellStyle();
        contStyle.setFont(contFont);
        contStyle.setBorderBottom(BorderStyle.THIN); //下边框
        contStyle.setBorderLeft(BorderStyle.THIN);//左边框
        contStyle.setBorderTop(BorderStyle.THIN);//上边框
        contStyle.setBorderRight(BorderStyle.THIN);//右边框
        contStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
        contStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直集中

        row = sheet.createRow(rowIndex++);
        row.setHeight((short) 500);//行高

        //创建表头
        createRyJpCellHead(headStyle, row);

        //填充数据
        createRyJpRow(rowIndex, contStyle, sheet, list);
        return wb;
	}
	
	private void createRyJpCellHead(HSSFCellStyle headStyle, Row row) {
        int columnIndex = 0;
        Cell cell = null;
        for (CellKey column : COLUMN_JP) {
            cell = row.createCell(columnIndex++);
            cell.setCellType(CellType.STRING);
            cell.setCellStyle(headStyle);
            cell.setCellValue(column.getHead());
        }
    }
	
	private void createRyJpRow(int rowIndex, HSSFCellStyle contStyle, Sheet sheet, List<HashMap> list) {
        int columnIndex = 0;
        Row row;
        for (HashMap map : list) {
            row = sheet.createRow(rowIndex++);
            row.setHeight((short) 500);//excel行高*20
            for (CellKey column : COLUMN_JP) {
                createCell(contStyle, row.createCell(columnIndex++), column, map);
            }
            columnIndex = 0;
        }
    }

	private List<HashMap> getRyxxJpListExport(HttpServletRequest request, String czr) {
		String gsmc = StrKits.emptyToStr(request.getParameter("gsmc"));
        String xgsmc = StrKits.emptyToStr(request.getParameter("xgsmc"));
        String lrr = StrKits.emptyToStr(request.getParameter("lrr"));
        String xm = StrKits.emptyToStr(request.getParameter("xm"));
        String ryzt = StrKits.emptyToStr(request.getParameter("ryzt"));
        String sfzhm = StrKits.emptyToStr(request.getParameter("sfzhm"));
        String cxrqq = StrKits.emptyToStr(request.getParameter("cxrqq"));
        String cxrqz = StringUtils.isEmpty(request.getParameter("cxrqz")) ? "" : request.getParameter("cxrqz") + " 23:59:59";
        String sort = StrKits.emptyToStr(request.getParameter("sort"));
        String order = StrKits.emptyToStr(request.getParameter("order"));

        return this.baseMapper.getRyxxJpListExport(lrr, gsmc, xgsmc, xm, ryzt, sfzhm, cxrqq, cxrqz, czr, StrKits.getOrderBy(sort, order));
	}

	@Override
	public DataGrid getRycxPageList(Page page, HttpServletRequest request, String czr) {
        page.setRecords(this.baseMapper.getRycxPageList(page, StrKits.emptyToStr(request.getParameter("tzxx_rycx_xm")),czr));
        return new DataGrid(page.getRecords(), page.getTotal());
	}
}
